package com.jxb.netty.network.nio.fileChannel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

public class Test {
    public static void main(String[] args) throws IOException {
        String sourcePath = "C:\\Users\\86177\\Documents\\learn\\product\\example\\example\\src\\main\\java\\com\\jiaoxiaobo\\network\\nio\\fileChannel\\1.txt";
        String destinationPath = "C:\\Users\\86177\\Documents\\learn\\product\\example\\example\\src\\main\\java\\com\\jiaoxiaobo\\network\\nio\\fileChannel\\destination.txt";
        try(
                FileInputStream source = new FileInputStream(sourcePath);
                FileOutputStream destination = new FileOutputStream(destinationPath);
                FileChannel sourceChannel = source.getChannel();
                FileChannel destinationChannel = destination.getChannel();
        ) {
            long size = sourceChannel.size();
            long positionInDestination = 0; // 从目标文件的0位置开始写入
            long l = destinationChannel.transferFrom(sourceChannel, positionInDestination, size);
            System.out.println("Bytes transferred: " + l);
        }
    }
}
